package com.dwxt.cdms.controller;

import com.dwxt.cdms.entity.Relation;
import com.dwxt.cdms.service.RelationService;
import com.dwxt.common.base.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/cdms/relation")
@RestController
public class RelationController {

    @Autowired
    private RelationService relationService;

    /**
     * 关联人绑定
     * @param relations
     * @return
     */
    @RequestMapping("/bind")
    public BaseResult bind(@RequestBody Relation[] relations){
        return relationService.insert(relations);
    }

    /**
     * 查询我关联的（可以看的）客户
     * @param customerId
     * @return
     */
    @RequestMapping("/selectRelationCustomer")
    public BaseResult selectRelationCustomer(Integer customerId,String type,String phone){
        return relationService.selectRelationCustomer(customerId,type,phone);
    }

    /**
     * 解绑
     * @param relation
     * @return
     */
    @RequestMapping("/unbind")
    public BaseResult unbind(Relation relation){
        return relationService.unbind(relation);
    }

    /**
     * 设置默认关联人
     * @param relation
     * @return
     */
    @RequestMapping("/setDefaultRelation")
    public BaseResult setDefaultRelation(Relation relation){
        return relationService.setDefaultRelation(relation);
    }

    /**
     * 查询可以看我的
     */
    @RequestMapping("/selectMyManagerCustomer")
    public BaseResult selectMyManagerCustomer(Integer customerId){
        return BaseResult.ok(relationService.selectMyManagerCustomer(customerId));
    }

    @RequestMapping("/update")
    public BaseResult update(Integer id,String relation){
        return relationService.update(id,relation);
    }

}
